/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jogo.Entidade;

/**
 *
 * @author IVAN
 */
public class Colisao {

    private double _width, _height;

    public boolean ColisaoTiroAtmosfera(Tiro tiro, Asteroide asteroid) {
        return (((double) (tiro.getR() + asteroid.getRGravitacional())) >= (Math.sqrt(Math.pow((double) (tiro.getCX() - asteroid.getCX()), (double) 2.0) + Math.pow((double) (tiro.getCY() - asteroid.getCY()), 2.0))));
    }

    public boolean ColisaoTiroAsteroide(Tiro tiro, Asteroide asteroid) {
        return (((double) (tiro.getR() + asteroid.getR())) >= (Math.sqrt(Math.pow((double) (tiro.getCX() - asteroid.getCX()), (double) 2.0) + Math.pow((double) (tiro.getCX() - asteroid.getCY()), 2.0))));
    }

    public boolean TiroForaCenario(Tiro tiro) {
        return ((tiro.getCX() + tiro.getR()) <= 0 || (tiro.getCX() - tiro.getR()) >= getWidth() || (tiro.getCY() + tiro.getR()) <= 0 || (tiro.getCY() - tiro.getR()) >= getHeight());
    }

    /**
     * @return the _width
     */
    public double getWidth() {
        return _width;
    }

    /**
     * @param width the _width to set
     */
    public void setWidth(double width) {
        this._width = width;
    }

    /**
     * @return the _height
     */
    public double getHeight() {
        return _height;
    }

    /**
     * @param height the _height to set
     */
    public void setHeight(double height) {
        this._height = height;
    }

    public void TiroDentroCampoGravitacional(Tiro tiro, Asteroide asteroid) {

        if (tiro.getCX() > asteroid.getCX() && tiro.getCY() > asteroid.getCY()) {
            tiro.Quadrante = 1;
        }
        if (tiro.getCX() < asteroid.getCX() && tiro.getCY() > asteroid.getCY()) {
            tiro.Quadrante = 2;
        }
        if (tiro.getCX() < asteroid.getCX() && tiro.getCY() < asteroid.getCY()) {
            tiro.Quadrante = 3;
        }
        if (tiro.getCX() > asteroid.getCX() && tiro.getCY() < asteroid.getCY()) {
            tiro.Quadrante = 4;
        }

        if (tiro.getCX() > asteroid.getCX() && tiro.getCY() == asteroid.getCY()) {
            tiro.Quadrante = 5;
        }
        if (tiro.getCX() == asteroid.getCX() && tiro.getCY() > asteroid.getCY()) {
            tiro.Quadrante = 6;
        }
        if (tiro.getCX() < asteroid.getCX() && tiro.getCY() == asteroid.getCY()) {
            tiro.Quadrante = 7;
        }
        if (tiro.getCX() == asteroid.getCX() && tiro.getCY() < asteroid.getCY()) {
            tiro.Quadrante = 8;
        }

    }

    public void Gravitacao(Tiro tiro, Asteroide asteroid) {
        tiro.GRAVITY_EFFECT = (15 * (asteroid.getGravidade()) / Math.pow(Distancia(tiro, asteroid), 1.07));
//        tiro.GRAVITY_EFFECT = (10 * (asteroid.getGravidade()) / Math.pow(Distancia(tiro, asteroid), 1.07));
    }

    private double Distancia(Tiro tiro, Asteroide asteroid) {
        double distancia = 0;

        distancia = (Math.sqrt(Math.pow((double) (tiro.getCX() - asteroid.getCX()), (double) 2.0) + Math.pow((double) (tiro.getCY() - asteroid.getCY()), 2.0)));

        return distancia;
    }
}
